#! /usr/bin/env python

def dec2bin(n):
    ret = ''
    while n:
        if n%2:
            ret = '1'+ret
        else:
            ret = '0'+ret
        n=n/2
    return ret
s=0
for i in range(1,1000000):
    dec = str(i)
    if dec == dec[::-1]:
        bin = str(dec2bin(i))
        if bin == bin[::-1]:
            s=s+i


print s
        
